import yaml
import logging.config
import os
import coloredlogs
#

def setup_logging(default_path='log.yaml', default_level=logging.INFO):
    """
    Setup logging configuration
    """
    logfile_path = os.path.split(default_path)
    # print(logfile_path)
    # print(logfile_path[0]+"/mylog")
    if os.path.exists(logfile_path[0]+"/mylog"):
        pass
    else:
        os.mkdir(logfile_path[0]+"/mylog")
    path = default_path
    if os.path.exists(path):
        with open(path, 'rt') as f:
            config = yaml.safe_load(f.read())
            # coloredlogs.DEFAULT_FIELD_STYLES = {'asctime': {'color': 'green'}, 'hostname': {'color': 'magenta'},
            #                                     'levelname': {'color': 'green', 'bold': True},
            #                                     'request_id': {'color': 'yellow'},
            #                                     'name': {'color': 'blue'}, 'programname': {'color': 'cyan'},
            #                                     'threadName': {'color': 'yellow'}}
            # fmt = '%(asctime)s [%(levelname)s] [%(name)s] %(filename)s[line:%(lineno)d] [%(threadName)s] %(message)s'
            logging.config.dictConfig(config)
            coloredlogs.install(level=logging.INFO)
    else:
        logging.basicConfig(level=default_level)
        print('the input path doesn\'t exist')



